package cn.stylefeng.guns.sys.modular.gslbDict.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.gslbDict.entity.Gslbzd;
import cn.stylefeng.guns.sys.modular.gslbDict.mapper.GslbzdMapper;
import cn.stylefeng.guns.sys.modular.gslbDict.model.params.GslbzdParam;
import cn.stylefeng.guns.sys.modular.gslbDict.model.result.GslbzdResult;
import cn.stylefeng.guns.sys.modular.gslbDict.service.GslbzdService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * <p>
 * 公示类别字典 服务实现类
 * </p>
 *
 * @author author
 * @since 2021-01-11
 */
@Service
public class GslbzdServiceImpl extends ServiceImpl<GslbzdMapper, Gslbzd> implements GslbzdService {

    @Override
    public void add(GslbzdParam param) {
        String val = UUID.randomUUID().toString();
        param.setGsxxbh(val);
        this.baseMapper.insertGslbzd(param);
    }

    @Override
    public void delete(GslbzdParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(GslbzdParam param) {
        Gslbzd oldEntity = getOldEntity(param);
        Gslbzd newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public GslbzdResult findBySpec(GslbzdParam param) {
        return null;
    }

    @Override
    public List<GslbzdResult> findListBySpec(GslbzdParam param) {
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(GslbzdParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public Integer selectDeleteInfo(String param) {
        return this.baseMapper.selectDelete(param);
    }

    @Override
    public void updateGslbzdInfo(GslbzdParam param) {
        this.baseMapper.updateGslbzd(param);
    }

    private Serializable getKey(GslbzdParam param) {
        return param.getGsxxbh();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Gslbzd getOldEntity(GslbzdParam param) {
        return this.getById(getKey(param));
    }

    private Gslbzd getEntity(GslbzdParam param) {
        Gslbzd entity = new Gslbzd();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
